package bairui.international.weixin.portal.miniapp.controller.college.college;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.data.querydsl.QSort;

import com.lianjing.sh.model.uml.model.status.State_UpDown;

import bairui.international.model.domain.jpa.TB_College;
import bairui.international.model.domain.jpa.TB_CollegeImage;
import bairui.international.model.type.Type_CollegeImage;
import bairui.international.service.Service_CollegeImage;
import lombok.Getter;

class Output {

	private @Getter Long id;
	private @Getter String title;
	private @Getter String comment;
	private @Getter String content;
	private @Getter String categoryName;
	private @Getter String date;
	private @Getter List<OutputImg> images = new ArrayList<>();
	private @Getter Boolean bigImgFlag;
	
	public Output(TB_College bean, Service_CollegeImage service_CollegeImage){
		this.id = bean.getId();
		this.title = bean.getTitle();
		this.content = bean.getContent();
		this.comment = bean.getComment();
		this.categoryName = bean.getCollegeCategory().getName();
		this.date = new SimpleDateFormat("yyyy/MM/dd").format(bean.getDate());
		this.bigImgFlag = bean.getBigImgFlag();
		//
		if(null != service_CollegeImage){
			this.images = service_CollegeImage.list(
					it->it.college.eq(bean).and(it.state.eq(State_UpDown.Uped)),
					it->new QSort(it.orderValue.desc(), it.createTime.desc())
				)
				.getContent()
				.stream()
				.map(it->new OutputImg(it))
				.collect(Collectors.toList());
		}
	}
	
	private static class OutputImg {
		@Getter private String url;
		@Getter private Type_CollegeImage format;
		OutputImg(TB_CollegeImage img){
			this.url = C_College_Show_ShowImg.ShowImg.Operate(img.getId()).getUrl();
			this.format = img.getFormat();
		}
	}
	
}
